package test_net;

import com.google.gson.Gson;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;

public class TestMapHttpCallback<V, H> extends AbsTestCallback<HttpResult<Map<V, H>>> {
    @Override
    public HttpResult<Map<V, H>> convert(String json) {

        Type type = getClass().getGenericSuperclass();
        Type[] types = ((ParameterizedType) type).getActualTypeArguments();
        ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(Map.class, new Type[]{types[0], types[1]});
        ParameterizedTypeImpl ty = new ParameterizedTypeImpl(HttpResult.class, new Type[]{mapType});
        return new Gson().fromJson(json, ty);
    }
}
